package com.reptile.handle;

import com.alibaba.fastjson.JSON;
import com.common.constant.YsConstant;
import com.reptile.context.BaseContext;
import com.reptile.dto.NewsDTO;
import com.reptile.mes.DingDingHelp;
import com.reptile.service.execute.*;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 技术新闻定时任务
 */
@Slf4j
@Component
public class YsTechnologyHandle {

    @Resource
    private DingDingHelp dingDingHelp;

    /**
     * 爬取CSDN热门话题数据
     */
    @XxlJob("YsReptileCSDNNewsHandler")
    public void CSDNNewsExecute() throws Exception {
        log.info("爬取CSDN热门话题数据！");
        BaseContext baseContext = new BaseContext(new CSDNBaseExecute());
        List<NewsDTO> result = baseContext.baseExecute();
        dingDingHelp.sendData(result, YsConstant.DING_DING_AlERT_TYPE_FEED_CARD);
        log.info("爬取CSDN热门话题数据！{}", JSON.toJSONString(result));
    }

    /**
     * 爬取开源中国技能专区数据
     */
    @XxlJob("YsKaiYDevelopingSkillsHandler")
    public void KaiYDevelopingSkillsExecute() throws Exception {
        log.info("爬取开源中国技能专区数据！");
        BaseContext baseContext = new BaseContext(new KaiYDevelopingSkillsExecute());
        List<NewsDTO> result = baseContext.baseExecute();
        dingDingHelp.sendData(result, YsConstant.DING_DING_AlERT_TYPE_FEED_CARD);
        log.info("爬取开源中国技能专区数据！{}", JSON.toJSONString(result));
    }

    /**
     * 爬取开源中国问答专区数据
     */
    @XxlJob("YsKaiYAnswersHandler")
    public void KaiYAnswersNewsExecute() throws Exception {
        log.info("爬取开源中国问答专区数据！");
        BaseContext baseContext = new BaseContext(new KaiYAnswersExecute());
        List<NewsDTO> result = baseContext.baseExecute();
        dingDingHelp.sendData(result, YsConstant.DING_DING_AlERT_TYPE_FEED_CARD);
        log.info("爬取开源中国问答专区数据！{}", JSON.toJSONString(result));
    }

    /**
     * 爬取开源中国综合资讯专区数据
     */
    @XxlJob("YsKaiYComprehensiveInfoHandler")
    public void KaiYComprehensiveInfoNewsExecute() throws Exception {
        log.info("爬取开源中国综合资讯专区数据！");
        BaseContext baseContext = new BaseContext(new KaiYComprehensiveInfoExecute());
        List<NewsDTO> result = baseContext.baseExecute();
        dingDingHelp.sendData(result, YsConstant.DING_DING_AlERT_TYPE_FEED_CARD);
        log.info("爬取开源中国综合资讯专区数据！{}", JSON.toJSONString(result));
    }

    /**
     * 爬取开源中国数据库专区数据
     */
    @XxlJob("YsKaiYDataBaseHandler")
    public void KaiYDataBaseNewsExecute() throws Exception {
        log.info("爬取开源中国数据库专区数据！");
        BaseContext baseContext = new BaseContext(new KaiYDataBaseExecute());
        List<NewsDTO> result = baseContext.baseExecute();
        dingDingHelp.sendData(result, YsConstant.DING_DING_AlERT_TYPE_FEED_CARD);
        log.info("爬取开源中国数据库专区数据！{}", JSON.toJSONString(result));
    }

    /**
     * 爬取开源中国软件更新专区数据
     */
    @XxlJob("YsKaiYSoftwareUpdateHandler")
    public void KaiYSoftwareUpdateNewsExecute() throws Exception {
        log.info("爬取开源中国软件更新专区数据！");
        BaseContext baseContext = new BaseContext(new KaiYSoftwareUpdateExecute());
        List<NewsDTO> result = baseContext.baseExecute();
        dingDingHelp.sendData(result, YsConstant.DING_DING_AlERT_TYPE_FEED_CARD);
        log.info("爬取开源中国软件更新专区数据！{}", JSON.toJSONString(result));
    }
}
